﻿#include "FITKGmshMshIOReader.h"
#include "FITKGmshAdaptorObject.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"

namespace Gmsh
{
    void FITKGmshMshIOReader::setComponentManager(Interface::FITKComponentManager* componentManager)
    {
        _componentMgr = componentManager;
    }

    void FITKGmshMshIOReader::run()
    {
        *_resultMark = false;
        bool ok = this->loadFile();
        if (!ok || !this->_data) return;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKGmshAdaptorObject>("Gmsh", "FITKGmshAdaptorObject");
        if (adaptor == nullptr) return;
        adaptor->setFileReader(this);
        adaptor->setDataObject(this->_data);
        if (_resultMark != nullptr)
            *_resultMark = adaptor->adaptR();
        else
            adaptor->adaptR();
        delete adaptor;

        //读取完成
        this->sendCurrentPercent(100);
    }

    void FITKGmshMshIOReader::consoleMessage(int level, const QString& message)
    {
        switch (level)
        {
        case 1: AppFrame::FITKMessageNormal(message);
            break;
        case 2: AppFrame::FITKMessageWarning(message);
            break;
        case 3: AppFrame::FITKMessageError(message);
            break;
        default:
            break;
        }
    }
}


